package org.jeecg.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.jeecg.common.constant.CacheConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @program: whp_backend
 * @description: AutoRefleshCache 切面执行类
 * @author: lixf
 * @create: 2023-05-26 10:29
 */
@Aspect
@Component
public class AutoRefleshCacheAspect {

    @Autowired
    public RedisTemplate<String, Object> redisTemplate;

    @Pointcut("@annotation(org.jeecg.common.aspect.annotation.AutoRefleshCache)")
    public void refleshPointCut() {

    }


    @Around("refleshPointCut()")
    public Object afterReturning(ProceedingJoinPoint point) throws Throwable {
        //执行方法
        Object result = point.proceed();

        //刷新缓存
        Set keys = redisTemplate.keys(CacheConstant.SYS_DICT_TABLE_CACHE + "*");
        redisTemplate.delete(keys);
        return result;
    }
}
